Remove `String` ownership constraint, fewer allocations.
authorCorey Farwell <coreyf@rwell.org>
Thu, 5 May 2016 23:07:36 +0000 (19:07 -0400)
committerCorey Farwell <coreyf@rwell.org>
Thu, 5 May 2016 23:07:36 +0000 (19:07 -0400)
src/cargo/core/package_id.rs
src/cargo/core/resolver/encode.rs
src/cargo/core/source.rs

index 0d968aeeef032a22f7023c43c8867f4f36591e66..bd3a66d94c897ac2419e9d157a0e2d0b4df4ca81 100644 (file)
@@ -44,7 +44,7 @@ impl Decodable for PackageId {
         let version = captures.at(2).unwrap();
         let url = captures.at(3).unwrap();
         let version = semver::Version::parse(version).ok().expect("invalid version");
-        let source_id = SourceId::from_url(url.to_string());
+        let source_id = SourceId::from_url(url);
 
         Ok(PackageId {
             inner: Arc::new(PackageIdInner {
index f81d620938bb09aec49cf4734455be1d4ff0a20c..6b3e3926fe5a9989a7ba53b08c37f78afcdb736b 100644 (file)
@@ -181,7 +181,7 @@ impl Decodable for EncodablePackageId {
 
         let source = captures.at(3);
 
-        let source_id = source.map(|s| SourceId::from_url(s.to_string()));
+        let source_id = source.map(|s| SourceId::from_url(s));
 
         Ok(EncodablePackageId {
             name: name.to_string(),
index 0bef76dbae49a57840665e5560bc1288be91d1c8..487e421eaa43ebc6987ef9d4a8acaffb21505197 100644 (file)
@@ -89,9 +89,9 @@ impl SourceId {
     /// use cargo::core::SourceId;
     /// SourceId::from_url("git+https://github.com/alexcrichton/\
     ///                     libssh2-static-sys#80e71a3021618eb05\
-    ///                     656c58fb7c5ef5f12bc747f".to_string());
+    ///                     656c58fb7c5ef5f12bc747f");
     /// ```
-    pub fn from_url(string: String) -> SourceId {
+    pub fn from_url(string: &str) -> SourceId {
         let mut parts = string.splitn(2, '+');
         let kind = parts.next().unwrap();
         let url = parts.next().unwrap();
@@ -268,7 +268,7 @@ impl Encodable for SourceId {
 impl Decodable for SourceId {
     fn decode<D: Decoder>(d: &mut D) -> Result<SourceId, D::Error> {
         let string: String = Decodable::decode(d).ok().expect("Invalid encoded SourceId");
-        Ok(SourceId::from_url(string))
+        Ok(SourceId::from_url(&string))
     }
 }